package zhxt.helmet.dao;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import zhxt.helmet.pojo.Camera;
import zhxt.helmet.pojo.User;

import java.util.List;

@Repository
public interface CameraDao {
    //根据block查
    @Select("select * from camera where block_id=#{blockId}")
    @Results({
            @Result(column = "block_id", property = "blockId"),
            @Result(column = "user_count", property = "userCount")
    })
    public List<Camera> selectByBlockId(int blockId);

    //查所有摄像头
    @Select("select * from camera")
    @Results({
            @Result(column = "block_id", property = "blockId"),
            @Result(column = "user_count", property = "userCount")
    })
    List<Camera> selectAllCameras();
    //根据id查url
    @Select("select COALESCE(url, '') from camera where id = #{id}")
    String queryURLById(int id);


    // 添加摄像头
    @Insert("insert into camera(block_id, url, user_count, working) "
            + "values(#{blockId}, #{url}, #{userCount}, #{working})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(Camera camera);

    //更新摄像头
    @Update("update camera  set " +
            "block_id=#{blockId}, " +
            "url=#{url} " +
            "user_count=#{userCount}"+
            "working=#{working}"+
            "where id=#{id}")
    void update(Camera camera);

    //删除摄像头
    @Delete("DELETE FROM camera WHERE id = #{id}")
    void delete(Camera camera);
}
